package com.red.star.wechat.data.mappers;

import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.Banner;
import com.red.star.wechat.data.entity.BannerExpand;
import com.red.star.wechat.data.entity.Mall;
import com.red.star.wechat.data.entity.MallBanner;
import com.red.star.wechat.data.entity.vo.MallBannerDataVo;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface BannerMapper extends MyMapper<Banner> {

    @Select("SELECT * FROM  t_mall_banner WHERE mall_code=#{mallCode}")
    List<MallBanner> findBannerOrderByMallCode(@Param("mallCode") String mallCode);

    @Select("SELECT * FROM  t_banner WHERE mall_code=#{mallCode}")
    List<Banner> findBannerByMallCode(@Param("mallCode") String mallCode);

    @Select("SELECT * FROM  t_banner WHERE id = #{bannerId}")
    Banner findBannerByBannerId(@Param("bannerId") Integer bannerId);

    @Select("SELECT * FROM  t_banner WHERE mall_code=#{mallCode} and sort is not null")
    List<Banner> findSortBannerByMallCode(@Param("mallCode") String mallCode);
    
	List<MallBannerDataVo> queryBannerData(@Param("userMallCode")String userMallCode,@Param("mallCode")String mallCode,@Param("bannerId")String bannerId, @Param("bannerName")String bannerName, @Param("status")String status,
			@Param("startTime")Date startTime, @Param("endTime")Date endTime);


	/** 
    * @Description: banner查询 
    * @Param: [bannerExpand] 
    * @return: java.util.List<BannerExpand>
    * @Author: liucancan
    * @Date: 2018/9/29 
    */ 
    List<BannerExpand> findBanner(BannerExpand bannerExpand);

    /**
     * @Description: 新增banner
     * @Author: liucancan
     * @Date: 2018/9/29
     */
    int insertBanner(BannerExpand bannerExpand);
    /**
     * @Description: 集团下发banner
     * @Author: liucancan
     * @Date: 2018/9/29
     */


	List<MallBannerDataVo> selectWorkableBanner(@Param("mallCode")String mallCode);

	@Update("UPDATE t_banner SET status =1,sort = #{sort},update_time = now()  WHERE id = #{bannerId}")
	void putawayBannerStatus(@Param("bannerId")String bannerId,@Param("sort") Integer sort);

	@Update("UPDATE t_banner SET status =2,update_time = now()  WHERE id = #{bannerId}")
	void removeBannerStatus(@Param("bannerId")String bannerId);

	List<MallBannerDataVo> selectValidBanner(@Param("mallCode")String mallCode);

	//查询所有已上线且在有效期内的banner
	List<Banner> findOnlineBannerByMallCode(@Param("mallCode")String mallCode);

	List<Mall> selectMallByMallCode(@Param("mallCode")String mallCode);


}
